import math


class Solution:
    def judgeSquareSum(self, c: int) -> bool:
        low = 0
        high = int(math.sqrt(c))

        while low <= high:
            r = low ** 2 + high ** 2
            if r < c:
                low += 1
            elif r > c:
                high -= 1
            else:
                return True

        return False
